<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>H+ 后台主题UI框架 - 空白页</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="__STATIC__/layout/favicon.ico">
    <link href="__STATIC__/layout/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/layout/css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="__STATIC__/layout/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/layout/css/style.css?v=4.1.0" rel="stylesheet">
    <link href="__STATIC__/layout/css/gyq.css" rel="stylesheet">
    <link rel="stylesheet" href="__STATIC__/layout/css/demo.css" type="text/css">
    <link href="__STATIC__/layout/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/plugins/webuploader/webuploader.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/layout/css/demo/webuploader-demo.css">
    <style>
        .radio-inline input[type=radio] {
            margin-top: 4px;
        }

        .checkManual:hover {
            text-decoration-line: underline;
            color: red;
        }
    </style>
</head>

<body style="color:#333;padding:3px; overflow-x: auto;">
<!-- 标题 -->
<div class="page-heade">
    <h1 class="title_color">入库确认单</h1>
</div>
<!-- 标题 -->
<div>
    <form action="" class="form-inline" id="form1">
        <input type="hidden" name="id" >
        <table class="row-margin-top tab-content table-bordered table" border="1" style="margin-bottom:0">
            <tr>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for=""
                                                                                     class="form-label">申请人：</label>
                </td>
                <td>{$sqr}<input type="hidden" name="sqr" value="{$sqr}"></td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">申请人部门：</label></td>
                <td>{$sqrbm}<input type="hidden" name="sqrbm" value="{$sqrbm}"></td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">申请日期：</label></td>
                <td>{$sqrq}<input type="hidden" value="{$sqrq}" name="sqrq"></td>
            </tr>
            <tr>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="" class="form-label">确认人：</label>
                </td>
                <td>{$qrr}<input type="hidden" name="qrr" value="{$qrr}"></td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">确认人部门：</label></td>
                <td>{$qrrbm}<input type="hidden" name="qrrbm" value="{$qrrbm}"></td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">确认日期：</label></td>
                <td>{$qrrq}<input type="hidden" name="qrrq" value="{$qrrq}"></td>
            </tr>
            <tr>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">入库方式：</label></td>
                <td>手动入库 <input type="hidden" name="rkfs" value="手动入库"></td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">对应仓库<span
                        class="colorRed">*</span>:</label></td>
                <td>
                    <select name="dyck" id="CorWare" class="form-control">
                        <option value="">请选择</option>
                        {volist name="ck" id="row"}
                        <option value="{$row.id}">{$row.ckjc}</option>
                        {/volist}
                    </select>
                </td>
                <td style="min-width: 160px;width: 160px" class="text-center"><label for="">物料类型<span
                        class="colorRed">*</span>:</label></td>
                <td>
                    <div class="wlKindText">
                        <select name="wllx" id="wlKind" class="form-control" onchange="func()">
                            <option value="">请选择</option>
                            <option value="1">销售物料</option>
                            <option value="2">生产物料</option>
                            <option value="3">成品</option>
                        </select>
                        <span class="helpText">帮</span>
                    </div>
                </td>
            </tr>
            <tr>
                <td style="min-width: 160px;width: 160px" class="text-center">
                    <label for="" class="form-label">入库原因<span class="colorRed">*</span>：</label>
                </td>
                <td colspan="5">
                    <input type="text" name="rkyy" class="form-control" id="manualReason" style="width: 50%">
                </td>
            </tr>
        </table>
        <table class="table table-bordered">
            <tr class="info">
                <th class="text-center" colspan="2"><span class="font-bold">物料明细</span>(至少添加一条物料明细)</th>
            </tr>
            <tr>
                <td colspan="2">
                    <button class="btn btn-info" type="button" id="addManual">添加入库明细</button>
                </td>
            </tr>
            <tr>
                <td colspan="2" id="manualInfo" style="border:0;padding: 1px;">
                    <table class="table table-bordered text-center" style="margin:0px;padding: 0;display: none;">
                        <thead>
                        <tr class="info">
                            <th class="text-center">序号</th>
                            <th class="text-center">操作</th>
                            <th class="text-center">编号</th>
                            <th class="text-center">名称</th>
                            <th class="text-center">供应商</th>
                            <th class="text-center">单位</th>
                            <th class="text-center">单价(元)</th>
                            <th class="text-center">数量</th>
                            <th class="text-center">金额(元)</th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                        <tfoot>

                        </tfoot>
                    </table>
                </td>
            </tr>
            <tr>
                <td style="min-width: 160px;width: 160px" class="text-center">
                    备注：
                </td>
                <td>
                    <textarea name="bz" id="" style="width: 70%;height: 70px;user-select:none"
                              class="form-control"></textarea><span style="vertical-align: bottom;">500</span>
                </td>
            </tr>
        </table>
        <div class="form-group white-bg" style="margin:20px 10px 20px 20px;">
            {if isset($attach)}
            <ul class="list-group">
                {volist name="attach" id="row"}
                <li class="list-group-item">
                    <a class="badge badge-primary removeIt" data-id="{$row.id}">移除</a>
                    <a href="{$row.path}" target="_blank">{$row.file_name}</a></li>
                {/volist}
            </ul>
            {/if}
            <div id="uploader" class="wu-example">
                <!--用来存放文件信息-->
                <div id="thelist" class="uploader-list"></div>
                <div class="btns">
                    <div id="picker">选择文件</div>
                    <button id="ctlBtn" class="btn btn-default">开始上传</button>
                </div>
                <input type="hidden" name="attach" id="attach">
                <input type="hidden" name="remove" id="remove">
            </div>
            <span>注：最多上传15个文件，每个文件小于50M,支持格式：</span><br>jpg,bnp,gif,png,jpeg,tif,raw,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,rar,zip,mp4,avi,rmvb,rm,mid,3gp,AVI,3GP,,mpg,mp3,wma,wav
        </div>

        <p><span class="lr_5"></span><label for="checkManual" class="checkbox colorRed"><input type="checkbox" name="qrrk"
                                                                                               id="checkManual" value="1"><a
                href="javascript:;" class="colorRed checkManual" id="">请确认信息填写无误并点选此按钮确认入库</a></label></p>
        <div class="row sub_btn" style="width:100%;text-align:center;padding: 20px 0">
            <input type="button" class="btn btn-success" id="saveCao"  value="确认入库">
            <input type="button" class="btn btn-warning" value="返回" onclick="back()">
        </div>
    </form>
</div>
<!-- 全局js -->
<script src="__STATIC__/layout/js/jquery.min.js?v=2.1.4"></script>
<script src="__STATIC__/layout/js/bootstrap.min.js?v=3.3.6"></script>
<!-- <script src="js/plugins/metisMenu/jquery.metisMenu.js"></script> -->
<script src="__STATIC__/layout/js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<!-- <script src="js/plugins/layer/laydate/laydate.js"></script> -->
<script src="__STATIC__/layout/js/plugins/layer/layer.min.js"></script>
<script src="__STATIC__/layout/js/plugins/sweetalert/sweetalert.min.js"></script>

<script>
    $('#saveCao').on('click',function () {
        if(!$('[name=qrrk]').is(':checked')){
            swal('请确认信息填写无误并点选确认按钮确认入库')
            return false
        }
        var list = []
        $('#manualInfo tbody tr').each(function (i,o) {
            list.push(unescape($(o).data('data')))
        })
        var jb = $(this).closest('form').serializeArray()

        $.post('',{jb:jb,list:list},function (data) {
            if(data.success){
                swal({title:data.msg},function () {
                    location.href='{:url("kcgl/kcgl")}'
                })
            }else{
                swal(data.msg,'','error')
            }
        },'json')
    })
    function back() {
        history.go(-1)
    }

    $("#addManual").click(function () {
        if ($("#CorWare").val() == 0) {
            swal("", "请选择对应仓库！", "error")
        } else if ($("#wlKind").val() == 0) {
            swal("", "请选择物料类型！", "error")
        } else if ($("#manualReason").val() == "") {
            swal("", "入库原因不能为空！", "error")
        } else {
            layer.open({
                type: 2,
                skin: 'layui-layer-rim', //加上边框
                area: ['800px', '500px'], //宽高
                title: "添加销售物料明细",
                content: 'manual_add_alert.html?wllx=' + $('[name=wllx]').val()
            });
        }
    })

    $("#saveUp").click(function () {
        if ($("#CorWare").val() == "") {
            swal("", "请至少添加一条物料明细！", "error")
        } else if ($("#wlKind").val() == 0) {
            swal("", "请选择物料类型！", "error")
        } else if ($("#manualReason").val() == "") {
            swal("", "入库原因不能为空！", "error")
        } else {

        }
    });
    $(document).on("click", ".modify_manual", function () {
        var index = $(this).closest('tr').index()
        var id = $(this).closest('tr').data('data')
        id = unescape(id)
        layer.open({
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            area: ['800px', '500px'], //宽高
            title: "修改销售物料明细",
            content: 'manual_update_alert.html?'+id+'&index='+index
        });
    })
    $(document).on("click", ".delThis", function () {
        var _this = $(this).closest('tr')
        var index = $(this).closest('tr').index()
        swal({
                title: "",
                text: "确定删除本条数据？",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false,
            },
            function () {

                $('#manualInfo').find('tbody tr:gt('+index+')').each(function (i,o) {
                    var aa = parseInt($(o).find('td:first-child').html())
                    aa--
                    $(o).find('td:first-child').html(aa)
                })
                _this.remove()
                var $xj_num=0
                var $xj_zje=0
                $("#manualInfo table").find('tbody').find('tr').each(function (i,o) {
                    $xj_num += parseInt($(o).find('td:nth-child(8)').html())
                    $xj_zje += parseInt($(o).find('td:last-child').html())
                })
                var xj = '<tr class="text-right font-bold"><td colspan="7">小计：</td><td>'+$xj_num+'</td><td>'+$xj_zje+'</td></tr>'
                $("#manualInfo table").find('tfoot').html(xj);

                    swal("删除！", "", "success");
            });
    })

    function func() {
        //获取被选中的option标签
        var vs = $('#wlKind  option:selected').text();
        var val = $('#wlKind').val();
        $(".wlKindText").html(vs+'<input name="wllx" type="hidden" value="'+val+'">');


    }
</script>
</body>

</html>
<script type="text/javascript">
    // 添加全局站点信息
    var BASE_URL = '__STATIC__/layout/js/plugins/webuploader';
</script>
<script src="__STATIC__/layout/js/plugins/webuploader/webuploader.min.js"></script>
<script type="text/javascript">
    // 文件上传
    jQuery(function() {
        var $ = jQuery,
            $list = $('#thelist'),
            $btn = $('#ctlBtn'),
            state = 'pending',
            uploader;

        var ids = [];
            uploader = WebUploader.create({

                // 不压缩image
                resize: false,

                // swf文件路径
                swf: BASE_URL + '/js/Uploader.swf',

                // 文件接收服务端。
                server: '{:url("upload/fileupload")}',

                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: '#picker'
            });

        // 当有文件添加进来的时候
        uploader.on( 'fileQueued', function( file ) {
            $list.append( '<div id="' + file.id + '" class="item">' +
                '<h4 class="info">' + file.name + '</h4>' +
                '<p class="state">等待上传...</p>' +
                '</div>' );
        });

        // 文件上传过程中创建进度条实时显示。
        uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
                $percent = $li.find('.progress .progress-bar');

            // 避免重复创建
            if ( !$percent.length ) {
                $percent = $('<div class="progress progress-striped active">' +
                    '<div class="progress-bar" role="progressbar" style="width: 0%">' +
                    '</div>' +
                    '</div>').appendTo( $li ).find('.progress-bar');
            }

            $li.find('p.state').text('上传中');

            $percent.css( 'width', percentage * 100 + '%' );
        });

        uploader.on( 'uploadSuccess', function( file,response) {
            if(response.success)
                ids.push(response.id)
            $( '#'+file.id ).find('p.state').text(response.msg);
        });

        uploader.on( 'uploadError', function( file ) {
            $( '#'+file.id ).find('p.state').text('上传出错');
        });

        uploader.on( 'uploadComplete', function( file ) {
            $('#attach').val(ids.join(','))
            $( '#'+file.id ).find('.progress').fadeOut();
        });

        uploader.on( 'all', function( type ) {
            if ( type === 'startUpload' ) {
                state = 'uploading';
            } else if ( type === 'stopUpload' ) {
                state = 'paused';
            } else if ( type === 'uploadFinished' ) {
                state = 'done';
            }

            if ( state === 'uploading' ) {
                $btn.text('暂停上传');
            } else {
                $btn.text('开始上传');
            }
        });

        $btn.on( 'click', function() {
            if ( state === 'uploading' ) {
                uploader.stop();
            } else {
                uploader.upload();
            }
            return false
        });
    })

</script>
</body>

</html>